package com.asm.slidingmenu;

import com.dspl.asmswd.R;

import java.text.DecimalFormat;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import com.asm.DBloader.ASM_FDaynPrdHedDS;
import com.asm.DBloader.ASM_FOrdDetDS;
import com.asm.DBloader.ASM_FOrdHedDS;
import com.asm.DBloader.ASM_FasmDS;
import com.asm.DBloader.ASM_FinvHedDS;
import com.asm.DBloader.ASM_UsersettingsDS;
import com.asm.DBloader.ASM_fASEDS;
import com.asm.DBloader.ASM_fDaynPrdDetDS;
import com.asm.DBloader.ASM_fSalRepDS;
import com.asm.slidingmenu.model.DateTimeParm;

import android.R.color;
import android.R.integer;
import android.R.menu;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.sax.RootElement;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.NavUtils;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.Space;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import android.support.v4.widget.DrawerLayout;
import android.widget.Toast;


public class ASM_Reports_fragment extends Fragment 
{
	
	public ASM_Reports_fragment () 
	{
		
	}

	public static EditText startdate = null;
	public static EditText enddate = null;
	private DrawerLayout mDrawerLayout;
	private ListView mDrawerList;
	private ActionBarDrawerToggle mDrawerToggle;
	private ViewGroup mContainerView;
	String ReportType,Repname,Repcode;
	private Double firstseconndlastTot = 0.00;
	private Double firstseconndlastProd = 0.00;
	private Double firstseconndlastAVG = 0.00;
	
	private Double LocationsalsesummerySKU = 0.00;
	private int LocationsalsesummeryTime;
	private Double LocationsalsesummeryVal = 0.00;
	
	


	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
	        Bundle savedInstanceState)
	{
		setHasOptionsMenu(true);  
	    View rootView = inflater.inflate(R.layout.asm_fragment_reports, container, false);
	    mContainerView = (ViewGroup)rootView.findViewById(R.id.container);
	    Viewhistory();
//		Fragment fragment = null;
//		fragment = new LineChartActivity1();
//		FragmentManager fragmentManager = getFragmentManager();
//		fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
	    return rootView;
	}

	
	public void reportgen() 
	{
		final Dialog dialog = new Dialog(getActivity());
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.asm_dialog_reportgen);
		dialog.setCancelable(false);
		
		
		  	Button btngen = (Button)dialog.findViewById(R.id.btngen);
			Button startbtn = (Button)dialog.findViewById(R.id.Startdate);
			Button endbtn = (Button)dialog.findViewById(R.id.enddate);
			Spinner spin1 = (Spinner)dialog.findViewById(R.id.spin1);
			Spinner spin2 = (Spinner)dialog.findViewById(R.id.spin2);
			final Spinner spin3 = (Spinner)dialog.findViewById(R.id.spin3);
			startdate   =(EditText)dialog.findViewById(R.id.editText1);
			enddate  =(EditText)dialog.findViewById(R.id.editText2);
			mDrawerLayout = (DrawerLayout)dialog.findViewById(R.id.drawer_layout);
			mDrawerList = (ListView)dialog.findViewById(R.id.list_slidermenu);
			Button btncancel = (Button)dialog.findViewById(R.id.btncancel);
			
			ASM_fSalRepDS ds2=new ASM_fSalRepDS(getActivity());
		
			
			ArrayList<String> list1 =ds2.getsalrep();
			list1.add(0,"'SELECT REP CODE'");
			ArrayAdapter<String> categoriesAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(), R.layout.item, list1);
			spin3.setAdapter(categoriesAdapter);
			spin3.setOnItemSelectedListener(new OnItemSelectedListener() 
			{

				@Override
				public void onItemSelected(AdapterView<?> parent, View view,
						int position, long id) {
					// TODO Auto-generated method stub
					Repcode =  parent.getItemAtPosition(position).toString();
				}

				@Override
				public void onNothingSelected(AdapterView<?> parent) {
					// TODO Auto-generated method stub
					
				}
			});
			
			
			List<String> list = new ArrayList<String>();
			list.add("'SELECT REPORTS TYPE'");
			list.add("1.SO LISTING");
			list.add("2.DAY SALES SUMMERY");
			list.add("3.SALES SUMMERY");
			list.add("4.ORDER INVOICE");
			list.add("5.INVOICE ORDER");
			list.add("6.RETURN INVOICE");
			list.add("7.DAILY SALES SUMMERY");
			list.add("8.CUMULATIVE SALES & STOCK SUMMERY");
			list.add("9.FREE ISSUE REIMBURSEMENT");
			list.add("10.FREE ISSUE SUMMERY");
			list.add("11.PENDING SO SUMMERY");
			list.add("12.STATEMENT OF BALANCE STOCK");
			list.add("13.TARGET ACTUAL REPORT - REP WISE");
			list.add("14.1st,2nd and LAST BILL SUMMERY");
			list.add("15.LOCATION SALES SUMMERY");

			
			ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item, list);
			dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
			spin1.setAdapter(dataAdapter);
			
			spin1.setOnItemSelectedListener(new OnItemSelectedListener() 
			{

				@Override
				public void onItemSelected(AdapterView<?> parent, View view,
						int position, long id) {
					// TODO Auto-generated method stub
					ReportType = parent.getItemAtPosition(position).toString();
					
				}

				@Override
				public void onNothingSelected(AdapterView<?> parent) {
					// TODO Auto-generated method stub
					
				}
			});
			
			btngen.setOnClickListener(new View.OnClickListener() 
			{
				
				@Override
				public void onClick(View v) 
				{
					// TODO Auto-generated method stub
					
				
					
					if(ReportType=="1.SO LISTING" && !startdate.getText().toString().equals(""))
					{
						if (Repcode!="'SELECT REP CODE'")
						{
							try 
							{
								
						
							ReprotViewSOListing(enddate.getText().toString(),startdate.getText().toString(),Repcode.toString());
							}
							catch (Exception e) 
							{
								// TODO: handle exception
								//Log.v("Error", "Error");
								AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
								builder1.setTitle("ERROR");
					            builder1.setMessage("NO DATA FOUND..CHECK YOUR DETAILS");
					            builder1.setIcon(R.drawable.ic_error);
					            builder1.setCancelable(true);
					            builder1.setPositiveButton("Ok",
					            new DialogInterface.OnClickListener()
					            {
					                public void onClick(DialogInterface dg, int id) 
					                {
					                	dg.dismiss();
					           
					                }
					            });
					            AlertDialog alert11 = builder1.create();
					            alert11.show();
							}
						}
						else 
						{
							AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
							builder1.setTitle("ATTENTION");
							builder1.setIcon(R.drawable.ic_attention);
				            builder1.setMessage("PLEASE SELECT REP CODE");
				            
				            builder1.setCancelable(true);
				            builder1.setPositiveButton("Ok",
				            new DialogInterface.OnClickListener()
				            {
				                public void onClick(DialogInterface dg, int id) 
				                {
				                	dg.dismiss();
				           
				                }
				            });
				            AlertDialog alert11 = builder1.create();
				            alert11.show();
						}
						
					
					
					}
					else if(ReportType=="9.FREE ISSUE REIMBURSEMENT" && !startdate.getText().toString().equals(""))
					{
						if (Repcode!="'SELECT REP CODE'")
						{
							try 
							{
								
						
							FreeIssueReimbrusementReport(enddate.getText().toString(),startdate.getText().toString(),Repcode.toString());
							}
							catch (Exception e) 
							{
								// TODO: handle exception
								//Log.v("Error", "Error");
								AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
								builder1.setTitle("ERROR");
					            builder1.setMessage("NO DATA FOUND..CHECK YOUR DETAILS");
					            builder1.setIcon(R.drawable.ic_error);
					            builder1.setCancelable(true);
					            builder1.setPositiveButton("Ok",
					            new DialogInterface.OnClickListener()
					            {
					                public void onClick(DialogInterface dg, int id) 
					                {
					                	dg.dismiss();
					           
					                }
					            });
					            AlertDialog alert11 = builder1.create();
					            alert11.show();
							}
						}
						else 
						{
							AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
							builder1.setTitle("ATTENTION");
							builder1.setIcon(R.drawable.ic_attention);
				            builder1.setMessage("PLEASE SELECT REP CODE");
				            
				            builder1.setCancelable(true);
				            builder1.setPositiveButton("Ok",
				            new DialogInterface.OnClickListener()
				            {
				                public void onClick(DialogInterface dg, int id) 
				                {
				                	dg.dismiss();
				           
				                }
				            });
				            AlertDialog alert11 = builder1.create();
				            alert11.show();
						}
					}
					else if (ReportType=="4.ORDER INVOICE" && !startdate.getText().toString().equals("")) 
					{
						if (Repcode!="'SELECT REP CODE'")
						{
							try 
							{
								
						
							OrderInvoiceReportRep(enddate.getText().toString(),startdate.getText().toString(),Repcode.toString());
							}
							catch (Exception e) 
							{
								// TODO: handle exception
								//Log.v("Error", "Error");
								AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
								builder1.setTitle("ERROR");
					            builder1.setMessage("NO DATA FOUND..CHECK YOUR DETAILS");
					            builder1.setIcon(R.drawable.ic_error);
					            builder1.setCancelable(true);
					            builder1.setPositiveButton("Ok",
					            new DialogInterface.OnClickListener()
					            {
					                public void onClick(DialogInterface dg, int id) 
					                {
					                	dg.dismiss();
					           
					                }
					            });
					            AlertDialog alert11 = builder1.create();
					            alert11.show();
							}
						}
						else 
						{
							AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
							builder1.setTitle("ATTENTION");
							builder1.setIcon(R.drawable.ic_attention);
				            builder1.setMessage("PLEASE SELECT REP CODE");
				            
				            builder1.setCancelable(true);
				            builder1.setPositiveButton("Ok",
				            new DialogInterface.OnClickListener()
				            {
				                public void onClick(DialogInterface dg, int id) 
				                {
				                	dg.dismiss();
				           
				                }
				            });
				            AlertDialog alert11 = builder1.create();
				            alert11.show();
						}
					}
					
					else if(ReportType=="15.LOCATION SALES SUMMERY" && !startdate.getText().toString().equals(""))
					{
						if (Repcode!="'SELECT REP CODE'")
						{
							try 
							{
								
						
							LocationSalesSummaryReport(enddate.getText().toString(),startdate.getText().toString(),Repcode.toString());
							}
							catch (Exception e) 
							{
								// TODO: handle exception
								//Log.v("Error", "Error");
								Log.v("Error", e.toString());
								AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
								builder1.setTitle("ERROR");
					            builder1.setMessage("NO DATA FOUND..CHECK YOUR DETAILS");
					            builder1.setIcon(R.drawable.ic_error);
					            builder1.setCancelable(true);
					            builder1.setPositiveButton("Ok",
					            new DialogInterface.OnClickListener()
					            {
					                public void onClick(DialogInterface dg, int id) 
					                {
					                	dg.dismiss();
					           
					                }
					            });
					            AlertDialog alert11 = builder1.create();
					            alert11.show();
							}
						}
						else 
						{
							AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
							builder1.setTitle("ATTENTION");
							builder1.setIcon(R.drawable.ic_attention);
				            builder1.setMessage("PLEASE SELECT REP CODE");
				            
				            builder1.setCancelable(true);
				            builder1.setPositiveButton("Ok",
				            new DialogInterface.OnClickListener()
				            {
				                public void onClick(DialogInterface dg, int id) 
				                {
				                	dg.dismiss();
				           
				                }
				            });
				            AlertDialog alert11 = builder1.create();
				            alert11.show();
						}
					}
					else if(ReportType=="14.1st,2nd and LAST BILL SUMMERY" && !startdate.getText().toString().equals(""))
					{
						//if (Repcode!="'SELECT REP CODE'")
						////{
						
							try 
							{
								
						
							Firstsecondlastbillsum(enddate.getText().toString(),startdate.getText().toString(),Repcode.toString());
							}
							catch (Exception e) 
							{
								// TODO: handle exception
								//Log.v("Error", "Error");
								Log.v("Error", e.toString());
								AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
								builder1.setTitle("ERROR");
					            builder1.setMessage("NO DATA FOUND..CHECK YOUR DETAILS");
					            builder1.setIcon(R.drawable.ic_error);
					            builder1.setCancelable(true);
					            builder1.setPositiveButton("Ok",
					            new DialogInterface.OnClickListener()
					            {
					                public void onClick(DialogInterface dg, int id) 
					                {
					                	dg.dismiss();
					           
					                }
					            });
					            AlertDialog alert11 = builder1.create();
					            alert11.show();
							}
						//}
//						else 
//						{
//							AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
//							builder1.setTitle("ATTENTION");
//							builder1.setIcon(R.drawable.ic_attention);
//				            builder1.setMessage("PLEASE SELECT REP CODE");
//				            
//				            builder1.setCancelable(true);
//				            builder1.setPositiveButton("Ok",
//				            new DialogInterface.OnClickListener()
//				            {
//				                public void onClick(DialogInterface dg, int id) 
//				                {
//				                	dg.dismiss();
//				           
//				                }
//				            });
//				            AlertDialog alert11 = builder1.create();
//				            alert11.show();
//						}
					}
//					z
//					else if (ReportType=="4.ORDER INVOICE" && !startdate.getText().toString().equals("")) 
//					{
//						if (Repcode!="'SELECT REP CODE'")
//						{
//							try 
//							{
//								
//						
//							OrderInvoiceReportRep(enddate.getText().toString(),startdate.getText().toString(),Repcode.toString());
//							}
//							catch (Exception e) 
//							{
//								// TODO: handle exception
//								//Log.v("Error", "Error");
//								AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
//								builder1.setTitle("ERROR");
//					            builder1.setMessage("NO DATA FOUND..CHECK YOUR DETAILS");
//					            builder1.setIcon(R.drawable.ic_error);
//					            builder1.setCancelable(true);
//					            builder1.setPositiveButton("Ok",
//					            new DialogInterface.OnClickListener()
//					            {
//					                public void onClick(DialogInterface dg, int id) 
//					                {
//					                	dg.dismiss();
//					           
//					                }
//					            });
//					            AlertDialog alert11 = builder1.create();
//					            alert11.show();
//							}
//						}
//						else 
//						{
//							AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
//							builder1.setTitle("ATTENTION");
//							builder1.setIcon(R.drawable.ic_attention);
//				            builder1.setMessage("PLEASE SELECT REP CODE");
//				            
//				            builder1.setCancelable(true);
//				            builder1.setPositiveButton("Ok",
//				            new DialogInterface.OnClickListener()
//				            {
//				                public void onClick(DialogInterface dg, int id) 
//				                {
//				                	dg.dismiss();
//				           
//				                }
//				            });
//				            AlertDialog alert11 = builder1.create();
//				            alert11.show();
//						}
//					}
					
					else 
					{
						AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
			            builder1.setMessage("PLEASE SELECT REPORT TYPE & DATE RANGE..");
			            builder1.setTitle("ATTENTION");
						builder1.setIcon(R.drawable.ic_attention);
			            builder1.setCancelable(true);
			            builder1.setPositiveButton("Ok",
			            new DialogInterface.OnClickListener()
			            {
			                public void onClick(DialogInterface dg, int id) 
			                {
			                	dg.dismiss();
			           
			                }
			            });
			            AlertDialog alert11 = builder1.create();
			            alert11.show();
						
					}
					
				}
			});
			
			startbtn.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) 
				{
					// TODO Auto-generated method stub
					datetimepicker("start");
				}
			});
			
			
			
			endbtn.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) 
				{
					// TODO Auto-generated method stub
					datetimepicker("end");
				}
			});
			
			btncancel.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					dialog.dismiss();
					
				}
			});
		
		dialog.show();
	}

	DateTimeParm parm =new DateTimeParm();
	

	
	public void datetimepicker(final String val)
	{
		
		final Dialog dialog = new Dialog(getActivity());
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.asm_fragment_datepicker);
		final DatePicker dtp  = (DatePicker)dialog.findViewById(R.id.dpResult);
		
		dialog.setCancelable(true);
		Button button = (Button)dialog.findViewById(R.id.btnok);	
		button.setOnClickListener(new View.OnClickListener() 
		
		{
			
			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
			
			DecimalFormat dateforFormat= new DecimalFormat("00");
			String date = dateforFormat.format(dtp.getDayOfMonth());
			String month = dateforFormat.format(dtp.getMonth() +1);
			int year = dtp.getYear();
			if(val=="start")
			{
				startdate.setText(year+"-"+month+"-"+date);
				dialog.dismiss();
			}
			else if (val=="end") 
			{
				enddate.setText(year+"-"+month+"-"+date);
				dialog.dismiss();	
			}
			
				
			}
		});
				
		dialog.show();
		
	}
	  private void Viewsummery(String repname,String amount) 
	    {
	        // Instantiate a new "row" view.
	        final ViewGroup newView = (ViewGroup) LayoutInflater.from(getActivity()).inflate(R.layout.list_item_examplereports, mContainerView, false);

	        	String[] sep = repname.split("-");
	        
	        	
	        	
				((TextView) newView.findViewById(android.R.id.text1)).setText(sep[0].toString());
			    ((TextView) newView.findViewById(android.R.id.text2)).setText("Total amount RS -: "+sep[1].toString());
	        mContainerView.addView(newView, 0);
	    }
	  public void Viewhistory() 
	  {
	        ASM_FOrdDetDS ASMname=new ASM_FOrdDetDS(getActivity());
	        ASM_UsersettingsDS ASMcode=new ASM_UsersettingsDS(getActivity());
	        ASM_FOrdHedDS ss=new ASM_FOrdHedDS(getActivity());
	        
	        
	        ASM_fSalRepDS Repname=new ASM_fSalRepDS(getActivity());
	        String ASMCode = ASMcode.getASMCode().toString().trim();
	        ArrayList<String> Repnames1 = Repname.getreplist(ASMCode);
	        ArrayList<String> totalamt  = ASMname.gettotamt(ASMCode);
	        
	        for (int i = 0; i < Repnames1.size(); i++)
	        {
	        	Viewsummery(Repnames1.get(i).toString(),"");
			}
	        
		
	  }
	 
	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
		switch (item.getItemId()) 
		{
		case R.id.action_add_item:
			reportgen();
			return true;
				default:
			return super.onOptionsItemSelected(item);
		}
	}
	public void ReprotViewSOListing(String startdate,String enddate,String Repcode)
	{
//		Fragment fragment = null;
//		fragment = new LineChartActivity1();
//		FragmentManager fragmentManager = getFragmentManager();
//		fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
		final Dialog dialog = new Dialog(getActivity());
		
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.asm_fragment_reportview);
		dialog.setCancelable(true);
		
		
		
		ASM_FOrdHedDS ds2=new ASM_FOrdHedDS(getActivity());
		ArrayList<String> list3 =ds2.getsolisting(startdate,enddate,Repcode);
		ArrayList<String> list4 =ds2.getsolisting1(startdate,enddate,Repcode);
		ArrayList<String> list5 =ds2.getsolisting2(startdate,enddate,Repcode);
		ArrayList<String> list6 =ds2.getsolisting3(startdate,enddate,Repcode);
		ArrayList<String> list7 =ds2.getsolisting4(startdate,enddate,Repcode);
		ArrayList<String> list8 =ds2.getsolisting5(startdate,enddate,Repcode);
		
		ArrayList<String> gettotalsum =ds2.gettotalsum(startdate,enddate,Repcode);
		
		ArrayAdapter<String> categoriesAdapter3 = new ArrayAdapter<String>(getActivity().getApplicationContext(), R.layout.item, list3);
		TextView txttitle = (TextView)dialog.findViewById(R.id.txttitle);
		TextView txtdetails = (TextView)dialog.findViewById(R.id.txtdetails);
		TextView txtsumery = (TextView)dialog.findViewById(R.id.txtsumery);
		
		
		ASM_fSalRepDS repanem=new ASM_fSalRepDS(getActivity());
		ArrayList<String> list1 =repanem.getsalrepname(Repcode);
		txttitle.setText("SALSE ORDER LISTING");
		txtdetails.setText("Rep Name -:-  "+list1.get(0).toString().trim()+"        "+"Name of Agent -:- "+"        "+"Area -:- ");
		txtsumery.setText("Pro.Calls -:-         "       +"NonPro.Calls -:-        "+"Total Calls -:-        "+ "Total for sales Rep -:- RS: "+gettotalsum.get(0).toString().trim());
	

		TableLayout stk = (TableLayout)dialog.findViewById(R.id.table_main);
        TableRow tbrow0 = new TableRow(getActivity());
        tbrow0.setGravity(Gravity.RIGHT);
        
        
        
        
        Button tv0 = new Button(getActivity());
        tv0.setText(" ORDER-NO ");
        tv0.setClickable(false);
        tv0.setTextSize(25);
        tv0.setTextColor(Color.GREEN);
        tv0.setGravity(Gravity.LEFT);
        tbrow0.addView(tv0);
        
        Button tv1 = new Button(getActivity());
        tv1.setText(" DATE ");
        tv1.setTextSize(25);
        tv1.setClickable(false);
        tv1.setGravity(Gravity.LEFT);
        tv1.setTextColor(Color.GREEN);
        tbrow0.addView(tv1);
        
        Button tv2 = new Button(getActivity());
        tv2.setText(" CUSTOMER ");
        tv2.setClickable(false);
        tv2.setTextSize(25);
        tv2.setGravity(Gravity.LEFT);
        tv2.setTextColor(Color.GREEN);
        tbrow0.addView(tv2);
        
        Button tv3 = new Button(getActivity());
        tv3.setText(" LOCATION ");
        tv3.setClickable(false);
        tv3.setTextSize(25);
        tv3.setGravity(Gravity.LEFT);
        tv3.setTextColor(Color.GREEN);
        tbrow0.addView(tv3);
        
        Button tv4 = new Button(getActivity());
        tv4.setText(" TIME ");
        tv4.setClickable(false);
        tv4.setTextSize(25);
        tv4.setGravity(Gravity.LEFT);
        tv4.setTextColor(Color.GREEN);
        tbrow0.addView(tv4);
        
        Button tv5 = new Button(getActivity());
        tv5.setText(" VALUE   ");
        tv5.setClickable(false);
        tv5.setTextSize(25);
        tv5.setGravity(Gravity.RIGHT);
        tv5.setTextColor(Color.GREEN);
        tbrow0.addView(tv5);
        

     
      
        
        
        stk.addView(tbrow0);
        
        for (int i = 0; i <categoriesAdapter3.getCount(); i++) 
        {
            TableRow tbrow = new TableRow(getActivity());
          
            
            Button t1v = new Button(getActivity());
            
            t1v.setText(categoriesAdapter3.getItem(i).toString().trim());
            t1v.setTextColor(Color.WHITE);
            t1v.setGravity(Gravity.LEFT);
            t1v.setClickable(false);
            tbrow.addView(t1v);
            
            Button t2v = new Button(getActivity());
            t2v.setText(" "+list4.get(i).toString().trim()+" ");
            t2v.setTextColor(Color.WHITE);
            t2v.setClickable(false);
            t2v.setGravity(Gravity.LEFT);
            tbrow.addView(t2v);
            
            Button t3v = new Button(getActivity());
            t3v.setText(" "+list5.get(i).toString().trim()+" ");
            t3v.setTextColor(Color.WHITE);
            t3v.setGravity(Gravity.LEFT);
            t3v.setClickable(false);
            tbrow.addView(t3v);
            
            Button t4v = new Button(getActivity());
            t4v.setText(" "+list6.get(i).toString().trim()+" ");
            t4v.setTextColor(Color.WHITE);
            t4v.setGravity(Gravity.LEFT);
            t4v.setClickable(false);
            tbrow.addView(t4v);
            
            Button t0v = new Button(getActivity());
            t0v.setText(" "+list7.get(i).toString().trim()+" ");
            t0v.setTextColor(Color.WHITE);
            t0v.setGravity(Gravity.LEFT);
            t0v.setClickable(false);
            tbrow.addView(t0v);
            
            Button t5v = new Button(getActivity());
            t5v.setText(" "+list8.get(i).toString().trim()+"    ");
            t5v.setTextColor(Color.WHITE);
            t5v.setGravity(Gravity.RIGHT);
            t5v.setClickable(false);
            tbrow.addView(t5v);
            stk.addView(tbrow);
        }

		
		dialog.show();
	}
	
	
	
	
	public void FreeIssueReimbrusementReport(String startdate,String enddate,String Repcode)
	{

		final Dialog dialog = new Dialog(getActivity());
		
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.asm_fragment_reportview);
		dialog.setCancelable(true);
		
		
		
		ASM_FOrdDetDS ds2=new ASM_FOrdDetDS(getActivity());
		ArrayList<String> list3 =ds2.getFreeissuerebdetails1(startdate,enddate,Repcode);
		ArrayList<String> list4 =ds2.getFreeissuerebdetails2(startdate,enddate,Repcode);
		ArrayList<String> list5 =ds2.getFreeissuerebdetails3(startdate,enddate,Repcode);
		ArrayList<String> list6 =ds2.getFreeissuerebdetails4(startdate,enddate,Repcode);
		ArrayList<String> list7 =ds2.getFreeissuerebdetails5(startdate,enddate,Repcode);
		ArrayList<String> list8 =ds2.getFreeissuerebdetails6(startdate,enddate,Repcode);
		ArrayList<String> list9 =ds2.getFreeisscount(startdate,enddate,Repcode);
		String getArea = ds2.getArea(startdate, enddate, Repcode);
		
		ASM_UsersettingsDS asc=new ASM_UsersettingsDS(getActivity());
		String ASmcode =asc.getASMCode();
		
		
		ASM_FasmDS ASMname=new ASM_FasmDS(getActivity());
		String nameASM = ASMname.getASMname(ASmcode);
		
		ArrayAdapter<String> categoriesAdapter3 = new ArrayAdapter<String>(getActivity().getApplicationContext(), R.layout.item, list3);
		TextView txttitle = (TextView)dialog.findViewById(R.id.txttitle);
		TextView txtdetails = (TextView)dialog.findViewById(R.id.txtdetails);
		TextView txtsumery = (TextView)dialog.findViewById(R.id.txtsumery);
		
		
		ASM_fASEDS repanem=new ASM_fASEDS(getActivity());
		String ASEName = repanem.getasename(ASmcode);
		txttitle.setText("FREE ISSUE REIMBURSEMENT");
		txtdetails.setText("ASM Name -:- "+nameASM+"     "+"ASE Name -:-"+ASEName+" "+"      "+"Region -:- "+getArea+"  ");
		txtsumery.setText("Date Period -:- "+startdate.toString()+"--"+enddate.toString()+"     "+"Distributor Name -:-  "+"Total Cases -:- "+list9.get(0).toString()+"   "+"Total Pieces -:- "+list9.get(1).toString()+"  " );
	

		TableLayout stk = (TableLayout)dialog.findViewById(R.id.table_main);
        TableRow tbrow0 = new TableRow(getActivity());
        tbrow0.setGravity(Gravity.RIGHT);
        
        
        
        
        Button tv0 = new Button(getActivity());
        tv0.setText(" INVOICE NO ");
        tv0.setClickable(false);
        tv0.setTextSize(25);
        tv0.setTextColor(Color.GREEN);
        tv0.setGravity(Gravity.LEFT);
        tbrow0.addView(tv0);
        
        Button tv1 = new Button(getActivity());
        tv1.setText(" DATE ");
        tv1.setTextSize(25);
        tv1.setClickable(false);
        tv1.setGravity(Gravity.LEFT);
        tv1.setTextColor(Color.GREEN);
        tbrow0.addView(tv1);
        
        Button tv2 = new Button(getActivity());
        tv2.setText(" RETAILER ");
        tv2.setClickable(false);
        tv2.setTextSize(25);
        tv2.setGravity(Gravity.LEFT);
        tv2.setTextColor(Color.GREEN);
        tbrow0.addView(tv2);
        
        Button tv6 = new Button(getActivity());
        tv6.setText(" ITEM NAME ");
        tv6.setClickable(false);
        tv6.setTextSize(25);
        tv6.setGravity(Gravity.LEFT);
        tv6.setTextColor(Color.RED);
        tbrow0.addView(tv6);
        
        Button tv3 = new Button(getActivity());
        tv3.setText(" CASES ");
        tv3.setClickable(false);
        tv3.setTextSize(25);
        tv3.setGravity(Gravity.LEFT);
        tv3.setTextColor(Color.RED);
        tbrow0.addView(tv3);
	        
        Button tv4 = new Button(getActivity());
        tv4.setText(" PIECES ");
        tv4.setClickable(false);
        tv4.setTextSize(25);
        tv4.setGravity(Gravity.LEFT);
        tv4.setTextColor(Color.YELLOW);
        tbrow0.addView(tv4);
        
        TextView tv7 = new TextView(getActivity());
        tv7.setText("  ");
        tv7.setClickable(false);
        tv7.setTextSize(25);
        tv7.setGravity(Gravity.LEFT);
        tv7.setTextColor(Color.YELLOW);
        tbrow0.addView(tv7);
      
        
        
        stk.addView(tbrow0);
        
        for (int i = 0; i <categoriesAdapter3.getCount(); i++) 
        {
            TableRow tbrow = new TableRow(getActivity());
          
            
            Button t1v = new Button(getActivity());
            
            t1v.setText(list3.get(i).toString().trim());
            t1v.setTextColor(Color.WHITE);
            t1v.setGravity(Gravity.LEFT);
            t1v.setClickable(false);
            tbrow.addView(t1v);
            
            Button t2v = new Button(getActivity());
            t2v.setText(list4.get(i).toString().trim());
            t2v.setTextColor(Color.WHITE);
            t2v.setClickable(false);
            t2v.setGravity(Gravity.LEFT);
            tbrow.addView(t2v);
            
            Button t3v = new Button(getActivity());
            t3v.setText(list5.get(i).toString().trim());
            t3v.setTextColor(Color.WHITE);
            t3v.setGravity(Gravity.LEFT);
            t3v.setClickable(false);
            tbrow.addView(t3v);
            
            Button t4v = new Button(getActivity());
            t4v.setText(list6.get(i).toString().trim());
            t4v.setTextColor(Color.WHITE);
            t4v.setGravity(Gravity.LEFT);
            t4v.setClickable(false);
            tbrow.addView(t4v);
            
            Button t0v = new Button(getActivity());
            t0v.setText(list7.get(i).toString().trim());
            t0v.setTextColor(Color.WHITE);
            t0v.setGravity(Gravity.LEFT);
            t0v.setClickable(false);
            tbrow.addView(t0v);
            
            Button t5v = new Button(getActivity());
            t5v.setText(list8.get(i).toString().trim());
            t5v.setTextColor(Color.WHITE);
            t5v.setGravity(Gravity.LEFT);
            t5v.setClickable(false);
            tbrow.addView(t5v);
            stk.addView(tbrow);

        }

		
		dialog.show();
	}
	
	
	public void OrderInvoiceReportRep(String startdate,String enddate,String Repcode)
	{

		final Dialog dialog = new Dialog(getActivity());
		
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.asm_fragment_reportview);
		dialog.setCancelable(true);
		
		
		
		ASM_FinvHedDS ds2=new ASM_FinvHedDS(getActivity());
		ArrayList<String> list3 =ds2.getInvoiceorderReport(startdate,enddate,Repcode);
		
		
		
	
		
		ASM_UsersettingsDS asc=new ASM_UsersettingsDS(getActivity());
		String ASmcode =asc.getASMCode();
		
		
		ASM_FasmDS ASMname=new ASM_FasmDS(getActivity());
		String nameASM = ASMname.getASMname(ASmcode);
		
		ArrayAdapter<String> categoriesAdapter3 = new ArrayAdapter<String>(getActivity().getApplicationContext(), R.layout.item, list3);
		TextView txttitle = (TextView)dialog.findViewById(R.id.txttitle);
		TextView txtdetails = (TextView)dialog.findViewById(R.id.txtdetails);
		TextView txtsumery = (TextView)dialog.findViewById(R.id.txtsumery);
		
		
		ASM_fASEDS repanem=new ASM_fASEDS(getActivity());
		String ASEName = repanem.getasename(ASmcode);
		txttitle.setText("ORDER INVOICE REPORT - REP WISE");
		txtdetails.setText("Rep Name -:- "+nameASM+"     "+"ASM Name -:-"+ASEName+" "+"      "+"Date Period -:-   ");
		txtsumery.setText("Total Order -:- --"+"Total Invoice -:-  "+"Total Return -:-   "+"Actual RD Amount -:-  " );
	

		TableLayout stk = (TableLayout)dialog.findViewById(R.id.table_main);
        TableRow tbrow0 = new TableRow(getActivity());
        tbrow0.setGravity(Gravity.RIGHT);
        
        
        
        
        Button tv0 = new Button(getActivity());
        tv0.setText(" ORDER DATE ");
        tv0.setClickable(false);
        tv0.setTextSize(25);
        tv0.setTextColor(Color.GREEN);
        tv0.setGravity(Gravity.LEFT);
        tbrow0.addView(tv0);
        
        Button tv1 = new Button(getActivity());
        tv1.setText(" ORDER NO ");
        tv1.setTextSize(25);
        tv1.setClickable(false);
        tv1.setGravity(Gravity.LEFT);
        tv1.setTextColor(Color.GREEN);
        tbrow0.addView(tv1);
        
        Button tv2 = new Button(getActivity());
        tv2.setText(" CUSTOMER NAME ");
        tv2.setClickable(false);
        tv2.setTextSize(25);
        tv2.setGravity(Gravity.LEFT);
        tv2.setTextColor(Color.GREEN);
        tbrow0.addView(tv2);
        
        Button tv6 = new Button(getActivity());
        tv6.setText(" ORDER VALUE ");
        tv6.setClickable(false);
        tv6.setTextSize(25);
        tv6.setGravity(Gravity.LEFT);
        tv6.setTextColor(Color.RED);
        tbrow0.addView(tv6);
        
        Button tv3 = new Button(getActivity());
        tv3.setText(" INVOICE DATE ");
        tv3.setClickable(false);
        tv3.setTextSize(25);
        tv3.setGravity(Gravity.LEFT);
        tv3.setTextColor(Color.RED);
        tbrow0.addView(tv3);
	        
        Button tv4 = new Button(getActivity());
        tv4.setText(" INVOICE VALUE ");
        tv4.setClickable(false);
        tv4.setTextSize(25);
        tv4.setGravity(Gravity.LEFT);
        tv4.setTextColor(Color.YELLOW);
        tbrow0.addView(tv4);
        
        Button tv7 = new Button(getActivity());
        tv7.setText(" RETURN DATE ");
        tv7.setClickable(false);
        tv7.setTextSize(25);
        tv7.setGravity(Gravity.LEFT);
        tv7.setTextColor(Color.YELLOW);
        tbrow0.addView(tv7);
        
        Button tv8 = new Button(getActivity());
        tv8.setText(" RETURN VALUE ");
        tv8.setClickable(false);
        tv8.setTextSize(25);
        tv8.setGravity(Gravity.LEFT);
        tv8.setTextColor(Color.YELLOW);
        tbrow0.addView(tv8);

        stk.addView(tbrow0);
        
        
        for (int i = 0; i <categoriesAdapter3.getCount(); i++) 
        {
            TableRow tbrow = new TableRow(getActivity());
          String Spe = list3.get(i).toString().trim();
          
          String[] Details = Spe.split("-");
            
            Button t1v = new Button(getActivity());
            
            t1v.setText(Details[0].toString());
            t1v.setTextColor(Color.WHITE);
            t1v.setGravity(Gravity.LEFT);
            t1v.setClickable(false);
            tbrow.addView(t1v);
            
            Button t2v = new Button(getActivity());
            t2v.setText(Details[1].toString());
            t2v.setTextColor(Color.WHITE);
            t2v.setClickable(false);
            t2v.setGravity(Gravity.LEFT);
            tbrow.addView(t2v);
            
            Button t3v = new Button(getActivity());
            t3v.setText(Details[2].toString());
            t3v.setTextColor(Color.WHITE);
            t3v.setGravity(Gravity.LEFT);
            t3v.setClickable(false);
            tbrow.addView(t3v);
            
            Button t4v = new Button(getActivity());
            t4v.setText(Details[3].toString());
            t4v.setTextColor(Color.WHITE);
            t4v.setGravity(Gravity.LEFT);
            t4v.setClickable(false);
            tbrow.addView(t4v);
            
            Button t0v = new Button(getActivity());
            t0v.setText(Details[4].toString());
            t0v.setTextColor(Color.WHITE);
            t0v.setGravity(Gravity.LEFT);
            t0v.setClickable(false);
            tbrow.addView(t0v);
            
            Button t5v = new Button(getActivity());
            t5v.setText(Details[5].toString());
            t5v.setTextColor(Color.WHITE);
            t5v.setGravity(Gravity.LEFT);
            t5v.setClickable(false);
            tbrow.addView(t5v);
            
            Button t6v = new Button(getActivity());
            t6v.setText(Details[6].toString());
            t6v.setTextColor(Color.WHITE);
            t6v.setGravity(Gravity.LEFT);
            t6v.setClickable(false);
            tbrow.addView(t6v);
            stk.addView(tbrow);

        }

		
		dialog.show();
	}
	
	 public boolean onKeyDown(int keyCode, KeyEvent event) {
	     if(keyCode==KeyEvent.KEYCODE_BACK)
	         Toast.makeText(getActivity(), "Use Home Button",      
	      Toast.LENGTH_LONG).show();

	     return false;
	        // Disable back button..............
	 }
	public void LocationSalesSummaryReport(String startdate,String enddate,String Repcode)
	{

		final Dialog dialog = new Dialog(getActivity());
		
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.asm_fragment_reportview);
		dialog.setCancelable(true);
		
		
		
		ASM_FOrdDetDS ds2=new ASM_FOrdDetDS(getActivity());
		ArrayList<String> list3 =ds2.getLocationRept(startdate,enddate,Repcode);
		
		ASM_UsersettingsDS asc=new ASM_UsersettingsDS(getActivity());
		String ASmcode =asc.getASMCode();
		
		
		ASM_FasmDS ASMname=new ASM_FasmDS(getActivity());
		String nameASM = ASMname.getASMname(ASmcode);
		
		ASM_fSalRepDS REPname=new ASM_fSalRepDS(getActivity());
		ArrayList<String> REPNAME = REPname.getsalrepname(Repcode);
		
		ArrayAdapter<String> categoriesAdapter3 = new ArrayAdapter<String>(getActivity().getApplicationContext(), R.layout.item, list3);
		TextView txttitle = (TextView)dialog.findViewById(R.id.txttitle);
		TextView txtdetails = (TextView)dialog.findViewById(R.id.txtdetails);
		TextView txtsumery = (TextView)dialog.findViewById(R.id.txtsumery);
		
		
		ASM_fASEDS repanem=new ASM_fASEDS(getActivity());
		String ASEName = repanem.getasename(ASmcode);
		
		txttitle.setText("Locations Sales Summary (Order)");
		txtdetails.setText("Rep Name -:- "+REPNAME.get(0).toString()+"     "+"ASM Name -:-"+nameASM+" "+"      "+"Date Period -:- "+startdate+" to "+enddate);
		
		
	

		TableLayout stk = (TableLayout)dialog.findViewById(R.id.table_main);
        TableRow tbrow0 = new TableRow(getActivity());
        tbrow0.setGravity(Gravity.RIGHT);
        
        
        
        
        Button tv0 = new Button(getActivity());
        tv0.setText(" INOVICE ");
        tv0.setClickable(false);
        tv0.setTextSize(25);
        tv0.setTextColor(Color.GREEN);
        tv0.setGravity(Gravity.LEFT);
        tbrow0.addView(tv0);
        
        Button tv1 = new Button(getActivity());
        tv1.setText(" DATE ");
        tv1.setTextSize(25);
        tv1.setClickable(false);
        tv1.setGravity(Gravity.LEFT);
        tv1.setTextColor(Color.GREEN);
        tbrow0.addView(tv1);
        
        Button tv2 = new Button(getActivity());
        tv2.setText(" TERRITORY ");
        tv2.setClickable(false);
        tv2.setTextSize(25);
        tv2.setGravity(Gravity.LEFT);
        tv2.setTextColor(Color.GREEN);
        tbrow0.addView(tv2);
        
        Button tv6 = new Button(getActivity());
        tv6.setText(" TIME ");
        tv6.setClickable(false);
        tv6.setTextSize(25);
        tv6.setGravity(Gravity.LEFT);
        tv6.setTextColor(Color.GREEN);
        tbrow0.addView(tv6);
        
        Button tv3 = new Button(getActivity());
        tv3.setText(" LOCATION ");
        tv3.setClickable(false);
        tv3.setTextSize(25);
        tv3.setGravity(Gravity.LEFT);
        tv3.setTextColor(Color.GREEN);
        tbrow0.addView(tv3);
	        
        Button tv4 = new Button(getActivity());
        tv4.setText(" OUTLET NAME ");
        tv4.setClickable(false);
        tv4.setTextSize(25);
        tv4.setGravity(Gravity.LEFT);
        tv4.setTextColor(Color.GREEN);
        tbrow0.addView(tv4);
        
        Button tv7 = new Button(getActivity());
        
        tv7.setText(" STARTING TIME GAP(Min) ");
        tv7.setClickable(false);
        tv7.setTextSize(25);
        tv7.setGravity(Gravity.LEFT);
        tv7.setTextColor(Color.GREEN);
        tbrow0.addView(tv7);
        
        Button tv8 = new Button(getActivity());
        tv8.setText(" NO Of SKU ");
        tv8.setClickable(false);
        tv8.setTextSize(25);
        tv8.setGravity(Gravity.LEFT);
        tv8.setTextColor(Color.GREEN);
        tbrow0.addView(tv8);
        
        Button tv9 = new Button(getActivity());
        tv9.setText("     TOTAL   VALUE    ");
        tv9.setClickable(false);
        tv9.setTextSize(25);
        tv9.setGravity(Gravity.LEFT);
        tv9.setTextColor(Color.GREEN);
        tbrow0.addView(tv9);
      
        
        
        stk.addView(tbrow0);
        
        for (int i = 0; i <categoriesAdapter3.getCount(); i++) 
        {
            TableRow tbrow = new TableRow(getActivity());
            
            String Spe = list3.get(i).toString().trim();
            
            String[] Details = Spe.split(":-:");
            
            String T1 = Details[0].toString();
            String T2 = Details[1].toString();
            String T3 = Details[2].toString();
            String T4 = Details[3].toString();
            String T5 = Details[4].toString();
            String T6 = Details[5].toString();
            String T7 = Details[6].toString();
            String T8 = Details[7].toString();
            Double T9 = Double.parseDouble(Details[8].toString());
            
        	 LocationsalsesummerySKU  = LocationsalsesummerySKU + Double.parseDouble(Details[7].toString());
        	 LocationsalsesummeryTime = LocationsalsesummeryTime + Integer.parseInt(T7);
        	 LocationsalsesummeryVal = LocationsalsesummeryVal + T9;
        	 
            txtsumery.setText("Avarage SKU -:- --"+"Total Duration -:- "+LocationsalsesummeryTime+"(Min)"+" No of SKU -:- "+LocationsalsesummerySKU+" Total Value-:- "+LocationsalsesummeryVal );
    
            
            Button t1v = new Button(getActivity());
            
            t1v.setText(T1.toString().trim());
            t1v.setTextColor(Color.WHITE);
            t1v.setGravity(Gravity.LEFT);
            t1v.setClickable(false);
            tbrow.addView(t1v);
            
            Button t2v = new Button(getActivity());
            t2v.setText(T2.toString().trim());
            t2v.setTextColor(Color.WHITE);
            t2v.setClickable(false);
            t2v.setGravity(Gravity.LEFT);
            tbrow.addView(t2v);
            
            Button t3v = new Button(getActivity());
            t3v.setText(T3.toString().trim());
            t3v.setTextColor(Color.WHITE);
            t3v.setGravity(Gravity.LEFT);
            t3v.setClickable(false);
            tbrow.addView(t3v);
            
            Button t4v = new Button(getActivity());
            t4v.setText(T4.toString().trim());
            t4v.setTextColor(Color.WHITE);
            t4v.setGravity(Gravity.LEFT);
            t4v.setClickable(false);
            tbrow.addView(t4v);
          
            
            Button t5v = new Button(getActivity());
            t5v.setText(T5.toString().trim());
            t5v.setTextColor(Color.WHITE);
            t5v.setGravity(Gravity.LEFT);
            t5v.setClickable(false);
            tbrow.addView(t5v);
            
            Button t6v = new Button(getActivity());
            t6v.setText(T6.toString().trim());
            t6v.setTextColor(Color.WHITE);
            t6v.setGravity(Gravity.LEFT);
            t6v.setClickable(false);
            tbrow.addView(t6v);
            
            Button t7v = new Button(getActivity());
            t7v.setText(T7.toString().trim());
            t7v.setTextColor(Color.WHITE);
            t7v.setGravity(Gravity.LEFT);
            t7v.setClickable(false);
            tbrow.addView(t7v);
            
            Button t8v = new Button(getActivity());
            t8v.setText(T8.toString().trim());
            t8v.setTextColor(Color.WHITE);
            t8v.setGravity(Gravity.LEFT);
            t8v.setClickable(false);
            tbrow.addView(t8v);
            
            Button t9v = new Button(getActivity());
            t9v.setText(T9.toString().trim());
            t9v.setTextColor(Color.WHITE);
            t9v.setGravity(Gravity.LEFT);
            t9v.setClickable(false);
            tbrow.addView(t9v);
            stk.addView(tbrow);
           
        }

		
		dialog.show();
	}
	
	public void Firstsecondlastbillsum(String startdate,String enddate,String Repcode)
	{

		
		final Dialog dialog = new Dialog(getActivity());
		
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.asm_fragment_reportview);
		dialog.setCancelable(true);
		
		
		

		
		
		ASM_UsersettingsDS asc=new ASM_UsersettingsDS(getActivity());
		String ASmcode =asc.getASMCode();
		
		
		ASM_FasmDS ASMname=new ASM_FasmDS(getActivity());
		String nameASM = ASMname.getASMname(ASmcode);
		
		//ArrayAdapter<String> categoriesAdapter3 = new ArrayAdapter<String>(getActivity().getApplicationContext(), R.layout.item, list3);
		TextView txttitle = (TextView)dialog.findViewById(R.id.txttitle);
		TextView txtdetails = (TextView)dialog.findViewById(R.id.txtdetails);
		TextView txtsumery = (TextView)dialog.findViewById(R.id.txtsumery);
		
		
		ASM_fASEDS repanem=new ASM_fASEDS(getActivity());
		String ASEName = repanem.getasename(ASmcode);
//		
//		  firstseconndlastTot =firstseconndlastTot + Double.parseDouble(T13);
//          firstseconndlastProd = firstseconndlastProd + Double.parseDouble(T12);
//          firstseconndlastAVG = firstseconndlastAVG + Double.parseDouble(T14);
		
		
	

		TableLayout stk = (TableLayout)dialog.findViewById(R.id.table_main);
        TableRow tbrow0 = new TableRow(getActivity());
        tbrow0.setGravity(Gravity.RIGHT);
        
        
        
        
        Button tv0 = new Button(getActivity());
        tv0.setText(" TERRITORY NAME ");
        tv0.setClickable(false);
        tv0.setTextSize(25);
        tv0.setTextColor(Color.GREEN);
        tv0.setGravity(Gravity.LEFT);
        tbrow0.addView(tv0);
        
        Button tv1 = new Button(getActivity());
        tv1.setText(" REP NAME ");
        tv1.setTextSize(25);
        tv1.setClickable(false);
        tv1.setGravity(Gravity.LEFT);
        tv1.setTextColor(Color.GREEN);
        tbrow0.addView(tv1);
        
        Button tv2 = new Button(getActivity());
        tv2.setText(" 1'st BILL AREA ");
        tv2.setClickable(false);
        tv2.setTextSize(25);
        tv2.setGravity(Gravity.LEFT);
        tv2.setTextColor(Color.GREEN);
        tbrow0.addView(tv2);
        
        Button tv6 = new Button(getActivity());
        tv6.setText(" TIME ");
        tv6.setClickable(false);
        tv6.setTextSize(25);
        tv6.setGravity(Gravity.LEFT);
        tv6.setTextColor(Color.GREEN);
        tbrow0.addView(tv6);
        
        Button tv3 = new Button(getActivity());
        tv3.setText(" VALUE ");
        tv3.setClickable(false);
        tv3.setTextSize(25);
        tv3.setGravity(Gravity.LEFT);
        tv3.setTextColor(Color.GREEN);
        tbrow0.addView(tv3);
	        
        Button tv4 = new Button(getActivity());
        tv4.setText(" 2'nd BILL AREA ");
        tv4.setClickable(false);
        tv4.setTextSize(25);
        tv4.setGravity(Gravity.LEFT);
        tv4.setTextColor(Color.GREEN);
        tbrow0.addView(tv4);
        
        Button tv7 = new Button(getActivity());
        tv7.setText(" TIME ");
        tv7.setClickable(false);
        tv7.setTextSize(25);
        tv7.setGravity(Gravity.LEFT);
        tv7.setTextColor(Color.GREEN);
        tbrow0.addView(tv7);
        
        Button tv8 = new Button(getActivity());
        tv8.setText(" VALUE ");
        tv8.setClickable(false);
        tv8.setTextSize(25);
        tv8.setGravity(Gravity.LEFT);
        tv8.setTextColor(Color.GREEN);
        tbrow0.addView(tv8);
        
        Button tv9 = new Button(getActivity());
        tv9.setText(" LAST BILL AREA ");
        tv9.setClickable(false);
        tv9.setTextSize(25);
        tv9.setGravity(Gravity.LEFT);
        tv9.setTextColor(Color.GREEN);
        tbrow0.addView(tv9);
        
        Button tv10 = new Button(getActivity());
        tv10.setText(" TIME ");
        tv10.setClickable(false);
        tv10.setTextSize(25);
        tv10.setGravity(Gravity.LEFT);
        tv10.setTextColor(Color.GREEN);
        tbrow0.addView(tv10);
        
        
        Button tv11 = new Button(getActivity());
        tv11.setText(" VALUE ");
        tv11.setClickable(false);
        tv11.setTextSize(25);
        tv11.setGravity(Gravity.LEFT);
        tv11.setTextColor(Color.GREEN);
        tbrow0.addView(tv11);
        
        Button tv12 = new Button(getActivity());
        tv12.setText(" PROD'CALL ");
        tv12.setClickable(false);
        tv12.setTextSize(25);
        tv12.setGravity(Gravity.LEFT);
        tv12.setTextColor(Color.GREEN);
        tbrow0.addView(tv12);
        
        Button tv13 = new Button(getActivity());
        tv13.setText(" TOTAL VALUE ");
        tv13.setClickable(false);
        tv13.setTextSize(25);
        tv13.setGravity(Gravity.LEFT);
        tv13.setTextColor(Color.GREEN);
        tbrow0.addView(tv13);
        
        Button tv14 = new Button(getActivity());
        tv14.setText("    AVARAGE    ");
        tv14.setClickable(false);
        tv14.setTextSize(25);
        tv14.setGravity(Gravity.LEFT);
        tv14.setTextColor(Color.GREEN);
        tbrow0.addView(tv14);
        
        
      
        
        
        stk.addView(tbrow0);
        
        
        ASM_fSalRepDS REP=new ASM_fSalRepDS(getActivity());
		ArrayList<String> REPcode =REP.getAllReps();
		for (int i = 0; i < REPcode.size(); i++) 
		{  
       // for (int i = 0; i <list3.size(); i++) 
			ASM_FOrdDetDS ds2=new ASM_FOrdDetDS(getActivity());
			ArrayList<String> list3 =ds2.getFirstsecondlastsummery(startdate,enddate,REPcode.get(i).toString().trim());

			ASM_FOrdDetDS ds4=new ASM_FOrdDetDS(getActivity());
			ArrayList<String> list4 =ds4.getFirstsecondlastsummerylast(startdate,enddate,REPcode.get(i).toString().trim());

			ASM_FOrdDetDS ds5=new ASM_FOrdDetDS(getActivity());
			ArrayList<String> list5 =ds5.getFirstsecondlastsummeryTotVal(startdate,enddate,REPcode.get(i).toString().trim());
			
       // {
        if (!list3.toString().endsWith("[]")) 
        {
			
		
            TableRow tbrow = new TableRow(getActivity());
            
            String Spe = list3.get(0).toString().trim();
            String Spe1 = list3.get(1).toString().trim();
            String last = list4.get(0).toString().trim();
            String TotVal = list5.get(0).toString().trim();
            
            
            
            
            
            String[] Details = Spe.split(":-:");
            String[] Details1 = Spe1.split(":-:");
            String[] Details2 = last.split(":-:");
            String[] Details3 = TotVal.split(":-:");
            
            String T1 = Details[0].toString();
            String T2 = Details[1].toString();
            
            String T3 = Details[2].toString();
            String T4 = Details[3].toString();
            String T5 = Details[4].toString();
            
            String T6 = Details1[2].toString();
            String T7 = Details1[3].toString();
            String T8 = Details1[4].toString();
            
            String T9 = Details2[2].toString();
            String T10 = Details2[3].toString();
            String T11 = Details2[4].toString();
            
            String T12 = Details3[0].toString();
            String T13 = Details3[1].toString();
            String T14 = Details3[2].toString();
            
            firstseconndlastTot =firstseconndlastTot + Double.parseDouble(T13);
            firstseconndlastProd = firstseconndlastProd + Double.parseDouble(T12);
            firstseconndlastAVG = firstseconndlastAVG + Double.parseDouble(T14);
//    
        	txttitle.setText("1'st AND 2'nd LAST BILL SUMMERY");
    		txtdetails.setText("ASM Name -:-"+nameASM+" "+"      "+"Date Period -:-"+startdate+ "to"+ startdate);
    		txtsumery.setText("Grand Total -:- --"+"Prod Call -:-"+firstseconndlastProd+  "Total Value -:-"+firstseconndlastTot+  "Avarage -:-"+firstseconndlastAVG );
    	
            
            Button t1v = new Button(getActivity());
            
            t1v.setText(T1.toString().trim());
            t1v.setTextColor(Color.WHITE);
            t1v.setGravity(Gravity.LEFT);
            t1v.setClickable(false);
            tbrow.addView(t1v);
            
            Button t2v = new Button(getActivity());
            t2v.setText(T2.toString().trim());
            t2v.setTextColor(Color.WHITE);
            t2v.setClickable(false);
            t2v.setGravity(Gravity.LEFT);
            tbrow.addView(t2v);
            
            Button t3v = new Button(getActivity());
            t3v.setText(T3.toString().trim());
            t3v.setTextColor(Color.WHITE);
            t3v.setGravity(Gravity.LEFT);
            t3v.setClickable(false);
            tbrow.addView(t3v);
            
            Button t4v = new Button(getActivity());
            t4v.setText(T4.toString().trim());
            t4v.setTextColor(Color.WHITE);
            t4v.setGravity(Gravity.LEFT);
            t4v.setClickable(false);
            tbrow.addView(t4v);
          
            
            Button t5v = new Button(getActivity());
            t5v.setText(T5.toString().trim());
            t5v.setTextColor(Color.WHITE);
            t5v.setGravity(Gravity.LEFT);
            t5v.setClickable(false);
            tbrow.addView(t5v);
            
            Button t6v = new Button(getActivity());
            t6v.setText(T6.toString().trim());
            t6v.setTextColor(Color.WHITE);
            t6v.setGravity(Gravity.LEFT);
            t6v.setClickable(false);
            tbrow.addView(t6v);
            
            Button t7v = new Button(getActivity());
            t7v.setText(T7.toString().trim());
            t7v.setTextColor(Color.WHITE);
            t7v.setGravity(Gravity.LEFT);
            t7v.setClickable(false);
            tbrow.addView(t7v);
            
            Button t8v = new Button(getActivity());
            t8v.setText(T8.toString().trim());
            t8v.setTextColor(Color.WHITE);
            t8v.setGravity(Gravity.LEFT);
            t8v.setClickable(false);
            tbrow.addView(t8v);
//            
            Button t9v = new Button(getActivity());
            t9v.setText(T9.toString().trim());
            t9v.setTextColor(Color.WHITE);
            t9v.setGravity(Gravity.LEFT);
            t9v.setClickable(false);
            tbrow.addView(t9v);

//            
            Button t10v = new Button(getActivity());
            t10v.setText(T10.toString().trim());
            t10v.setTextColor(Color.WHITE);
            t10v.setGravity(Gravity.LEFT);
            t10v.setClickable(false);
            tbrow.addView(t10v);

//            
            Button t11v = new Button(getActivity());
            t11v.setText(T11.toString().trim());
            t11v.setTextColor(Color.WHITE);
            t11v.setGravity(Gravity.LEFT);
            t11v.setClickable(false);
            tbrow.addView(t11v);

//            
            Button t12v = new Button(getActivity());
            t12v.setText(T12.toString().trim());
            t12v.setTextColor(Color.WHITE);
            t12v.setGravity(Gravity.LEFT);
            t12v.setClickable(false);
            tbrow.addView(t12v);

//            
            Button t13v = new Button(getActivity());
            t13v.setText(T13.toString().trim());
            t13v.setTextColor(Color.WHITE);
            t13v.setGravity(Gravity.LEFT);
            t13v.setClickable(false);
            tbrow.addView(t13v);

//            
            Button t14v = new Button(getActivity());
            t14v.setText(T14.toString().trim());
            t14v.setTextColor(Color.WHITE);
            t14v.setGravity(Gravity.LEFT);
            t14v.setClickable(false);
            tbrow.addView(t14v);
            stk.addView(tbrow);
           
      //  }

        }
		}
		dialog.show();
	
	}
	
}
